package client

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/client"
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var ClientUserGroup = core.Group("/client", newUserHandler, regClientUser, middleware.TokenAuth())

func newUserHandler(srv client.IClientUserService) *clientuserHandler {
	return &clientuserHandler{srv: srv}
}

func regClientUser(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *clientuserHandler) {
		rg.GET("/client_user/list", handle.list)
		rg.GET("/client_user/detail", handle.detail)
		rg.POST("/client_user/del", handle.del)
	})
}

type clientuserHandler struct {
	srv client.IClientUserService
}

// list user列表
func (hd clientuserHandler) list(c *gin.Context) {
	var page request.PageReq
	var listReq req.ClientUserListReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}
	res, err := hd.srv.List(c, page, listReq)
	response.CheckAndRespWithData(c, res, err)
}

// detail user详情
func (hd clientuserHandler) detail(c *gin.Context) {
	var detailReq req.ClientUserDetailReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
		return
	}
	res, err := hd.srv.Detail(detailReq.Id)
	response.CheckAndRespWithData(c, res, err)
}

// del user删除
func (hd clientuserHandler) del(c *gin.Context) {
	var delReq req.ClientUserDelReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Del(delReq.Id))
}
